<html>

<head>
    <script type="text/javascript" src="jquery.js"></script>
    <meta http-equiv="Content-Type" content="text/html; charset=utf8">
    <title>js</title>


</head>

<body>
    <!--<button onclick="window.open('ceeloConsole:','_self')">-->
    <!--打开控制器-->
    <!--</button>-->
    <button id="playDota" onclick="window.open('ceeloConsole:','_self')">启动DOTA2</button>
    <button id="teamFightBt">团战跳转</button>
    <a href="http://127.0.0.1:9090/cmd?cmd=playdemo replays/3261175755.dem">123</a>
    <a href="http://127.0.0.1:9090/teamfight?startTick=40000">123</a>

</body>
<script language="JavaScript">
    $('#playDota').click(function() {
        location.href = "steam://run/570//-perfectworld -vconsole"
    })

    $("#teamFightBt").click(function() {
        var ws = new WebSocket("ws://localhost:9099/playdemo");
        ws.onopen = function() {
            ws.send("3054488401");
        }
        var params_tick = "40000"
        ws.onerror = function(err) {
            // alert("连接不上websocket，尝试打开ceeloConsole");
            var wd = window.open('ceeloConsole:', '_self')
            console.log(wd)
            if (wd) {
                wd.onabort = function() {
                    console.log("xxxx")
                }
                wd.onfocus = function() {
                    console.log("yyyy")
                }
            }
        }
        ws.onmessage = function(data) {
            data = JSON.parse(data.data)
            console.log(data)
            switch (data.Status) {
                case 1:
                    location.href = "steam://run/570//-perfectworld -vconsole"
                    break;
                case 0:
                case 3:
                    console.log("xxx")
                    var goto_ws = new WebSocket("ws://localhost:9099/teamfight");
                    goto_ws.onmessage = function(data) {
                        console.log("gotoTick", data.Status)
                        goto_ws.close()
                    }
                    goto_ws.onopen = function() {
                        console.log("tick", params_tick)
                        goto_ws.send(params_tick)
                    }
                    break;
                case 2:
                case 4:
                case 5:
                    alert(data.Text)
                    break;
                default:
                    break;
            }
            ws.close()
        };
    });
</script>

</html>